package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventWgbgBo;
import com.ruoyi.event.domain.vo.EventWgbgVo;
import com.ruoyi.event.service.IEventWgbgService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 违规报告
 *
 * @author strongme
 * @date 2023-02-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/wgbg")
public class EventWgbgController extends BaseController {

    private final IEventWgbgService iEventWgbgService;

    /**
     * 查询违规报告列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventWgbgVo> list(EventWgbgBo bo, PageQuery pageQuery) {
        return iEventWgbgService.queryPageList(bo, pageQuery);
    }

    @PostMapping("query")
    public R<List<EventWgbgVo>> query(@RequestBody EventWgbgBo bo) {
        return R.ok(iEventWgbgService.queryList(bo));
    }

    /**
     * 导出违规报告列表
     */
    @Log(title = "违规报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventWgbgBo bo, HttpServletResponse response) {
        List<EventWgbgVo> list = iEventWgbgService.queryList(bo);
        ExcelUtil.exportExcel(list, "违规报告", EventWgbgVo.class, response);
    }

    /**
     * 获取违规报告详细信息
     *
     * @param wgbgId 主键
     */
    @GetMapping("/{wgbgId}")
    public R<EventWgbgVo> getInfo(@NotNull(message = "主键不能为空")
                                  @PathVariable Long wgbgId) {
        return R.ok(iEventWgbgService.queryById(wgbgId));
    }

    /**
     * 新增违规报告
     */
    @Log(title = "违规报告", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventWgbgBo bo) {
        return toAjax(iEventWgbgService.insertByBo(bo));
    }

    /**
     * 修改违规报告
     */
    @Log(title = "违规报告", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventWgbgBo bo) {
        return toAjax(iEventWgbgService.updateByBo(bo));
    }

    /**
     * 删除违规报告
     *
     * @param wgbgIds 主键串
     */
    @Log(title = "违规报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wgbgIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] wgbgIds) {
        return toAjax(iEventWgbgService.deleteWithValidByIds(Arrays.asList(wgbgIds), true));
    }
}
